#include <iostream>
#include <algorithm>
using namespace std;

#define MAX_COUNT 128

int LCS( int* seq1, int* seq2, int len1, int len2 )
{
	int F[ MAX_COUNT ] = {0};

	for( int i = 1; i <= len2; i++ )
	{
		int t = F[0];
		for( int j = 1; j <= len1; j++ )
		{
			int q = F[j];
			if( seq2[i-1] == seq1[j-1] )
			{
				F[j] = t + 1;
			}
			else
			{
				F[j] = max( F[j], F[j-1] );
			}
			t = q;
		}
	}

	return F[ len1 ];
}

int main( int argc, char* argv[] )
{
	int seq1[ MAX_COUNT ] = {0};
	int seq2[ MAX_COUNT ] = {0};

	int c = 1;

	while( 1 )
	{

		int len1 = 0;
		int len2 = 0;
		cin >> len1 >> len2;

		if( len1 == 0 || len2 == 0 ) break;

		for( int i = 0; i < len1; i++ ) cin >> seq1[i];
		for( int i = 0; i < len2; i++ ) cin >> seq2[i];

		cout << "Twin Towers #" << c << endl;
		cout << "Number of Tiles : " << LCS( seq1, seq2, len1, len2 ) << "\n" << endl;
		c++;

	}

	return 0;
}
